package com.night.icm.persistence.base.repository;

import com.night.icm.persistence.base.entity.SystemDictionaryValue;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * SystemDictionaryValueRepository
 *
 * @author Liao ZhiYong
 * @date 2019/12/22
 */
@Repository
public interface SystemDictionaryValueRepository extends JpaRepository<SystemDictionaryValue, Long>, JpaSpecificationExecutor<SystemDictionaryValue> {

    /**
     * 通过字典Id与字典值的key组查询字典值
     *
     * @param dictionaryId 字典ID
     * @param valueKey     字典值
     * @return 字典值Id
     */
    @Query(value = "select v.id from SystemDictionaryValue as v where v.key = :valueKey and v.dictionary.id = :dictionaryId")
    Long findByDictionaryAndKey(@Param("dictionaryId") Long dictionaryId, @Param("valueKey") String valueKey);
}
